package binaryTree;


//计算一颗二叉树有多少个节点　
public class PostTraverseFindSubTreeLeafNum {
//    int num=0;
    public  int subTreeLeafNums(TreeNode  root){
        if ( root==null){
            return 0;
        }
          return  traverse(root);
//        return  num;
    }
    //使用后序遍历
    public  int  traverse(TreeNode  root){
        if (root==null){
            return 0;
        }
        int left = traverse(root.left);
        int right = traverse(root.right);
//        todo:自己的错误写法
//        return  left+right;
//todo:正确的写法
        return  left+right+1;

    }

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(0);
        TreeNode treeNode3 = new TreeNode(48);
        TreeNode treeNode4 = new TreeNode(12);
        TreeNode treeNode5 = new TreeNode(49);
        treeNode1.left=treeNode2;
        treeNode1.right=treeNode3;
        treeNode3.left=treeNode4;
        treeNode3.right=treeNode5;
        PostTraverseFindSubTreeLeafNum postTraverseFindSubTreeLeafNum = new PostTraverseFindSubTreeLeafNum();
        System.out.println(postTraverseFindSubTreeLeafNum.subTreeLeafNums(treeNode1));


    }



}
